<template>
  <div v-if="show" class="fontDa">
    <div class="customTableHeader">
      <div class="customTableTitle">{{ cepingHdglCppmxbInfo.cppName }}</div>
    </div>
   <div class="fontDa">
    <div class="zhaoPian">
      <div style="padding-bottom: 10px;">单位：{{cepingHdglCppmxbInfo.sheetDept}}</div>
    </div>
    <div class="cpTable">
        <el-table ref="report-table" :data="tableData" :span-method="objectSpanMethod" border :row-class-name="tableRowClassName">
        <el-table-column  type="index"  label="序号" header-align="center" align="center" width="70"></el-table-column>
        <el-table-column label="被评议对象的基本情况" align="center" min-width="300">
          <el-table-column v-for="col in colShowAll" :prop="col.prop" :label="col.label">
          </el-table-column>
        </el-table-column>
        <el-table-column label="对提拔任用该干部的看法" align="center" min-width="300">
          <el-table-column v-for="(gz,j) in tableColumn" :key="j+10000" :label="gz.optName":fzIndex="j" align="center" min-width="50">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-success" class="cpCheck" v-if="scope.row.wxOpenid == gz.optId" ></el-button>
            <el-button type="text" class="cpCheck" v-else @click="cpDaFen(scope.$index,gz,scope.row)"><i class="noChecked"></i></el-button>
          </template>
        </el-table-column>
        </el-table-column>
      </el-table>
      <template v-for="(questionList,indexs) in qList">
        <div style="width: 100%;margin-top: 25px;" class="zfheaderbox sub">
           <div style="font-size: 24px;">{{indexs+1}}、{{questionList.title}}</div>
        </div>
        <div style="width: 100%;" class="zfheaderbox">
          <!--              placeholder="新选拔任用领导人员民主评议表"-->
          <el-input
            @change="submit(questionList)"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 10}"
            size="medium"
            v-model="questionList.answer">
          </el-input>
        </div>
      </template>
      </div>
    </div>
  </div>

</template>

<script>
import {xpInfo,daFenCp,delDaFenCp,daFenCpAnswer,xpInfoSm} from "@/api/ceping/jxevalvote";
export default {
  name: "cpIndexXp",
  data() {
    return {
      shuxing:"top-end",
      answer:"",
      cppId:"",
      xpCode:"",
      hdId:"",
      show: false,
      df: true,
      cepingHdglXpxxb: {},
      cepingHdglCppmxbInfo: {},
      fzbList: [],
      tableColumn: [],
      tableHeader: [],
      msgList:[],
      voteAnsList:[],
      answerJson:[],
      tableData: [

      ],
      colShowAll:[

      ],
      questionList:[],
      qList:[],
      cepingHdglXpxxbList:[],
      userId:0
    }
  },
  methods: {
    //选票（实名）
    initHd(hdId,cppId,userId) {
      this.show = false;
      this.df = true;
      this.cppId = cppId;
      this.hdId=hdId;
      this.userId = userId
      let params ={
        cppId:cppId,
        hdId:hdId,
        userId:userId
      }
      xpInfoSm(params).then(res => {
        this.cepingHdglCppmxbInfo = res.data.data.cepingHdglCppmxbInfo;
        this.voteAnsList = res.data.data.voteAnsList;
        this.cepingHdglXpxxbList = res.data.data.cepingHdglXpxxbList;
        this.tableColumn = res.data.data.cepingHdglXpxxDfjlbList;
        this.tableData = res.data.data.userList;
        this.tableData.forEach(item=>{
                if(item.rySr){
                  item.rySr = item.rySr.substring(0,7)
                }
              })
        this.msgList = JSON.parse(res.data.data.cepingHdglCppmxbInfo.ruleDetailJson)
        this.hdId = res.data.data.cepingHdglCppmxbInfo.hdId;
        this.qList.splice(0)
        this.msgList.forEach(item=>{
          if(item.itemType == 1){

          }else if(item.itemType == 3){
            var voteObj = this.voteAnsList.find(voteItem => voteItem.itemId == item.itemId);
            var pushObj={
              answer:'',
              title:item.title,
              itemId:item.itemId,
            }
            if(voteObj){
              pushObj.answer=voteObj.answer
              this.qList.push(pushObj)
            }else{
              this.qList.push(pushObj)

            }
          }
        })
        this.init();
      })
    },
    //选票（匿名）
    initXp(cppId,xpCode) {
      this.show = false;
      this.df = true;
      this.cppId = cppId;
      this.xpCode = xpCode;
      this.userId = 0;
      let params ={
        cppId:cppId,
        xpCode:xpCode
      }
      xpInfo(params).then(res => {
        this.cepingHdglCppmxbInfo = res.data.data.cepingHdglCppmxbInfo;
        this.voteAnsList = res.data.data.voteAnsList;
        this.cepingHdglXpxxbList = res.data.data.cepingHdglXpxxbList;
        this.tableColumn = res.data.data.cepingHdglXpxxDfjlbList;
        this.tableData = res.data.data.userList;
        this.tableData.forEach(item=>{
                if(item.rySr){
                  item.rySr = item.rySr.substring(0,7)
                }
              })
        this.msgList = JSON.parse(res.data.data.cepingHdglCppmxbInfo.ruleDetailJson)
        this.hdId = res.data.data.cepingHdglCppmxbInfo.hdId;
        this.qList.splice(0);
        this.msgList.forEach(item=>{
          if(item.itemType == 1){

          }else if(item.itemType == 3){
             var voteObj = this.voteAnsList.find(voteItem => voteItem.itemId == item.itemId);
                var pushObj={
                answer:'',
                title:item.title,
                itemId:item.itemId,
              }
            if(voteObj){
              pushObj.answer=voteObj.answer
             this.qList.push(pushObj)
            }else{
             this.qList.push(pushObj)

            }
          }
        })
        this.init();
      })
    },
    init(){
      this.show = true;
      this.colShowAll = JSON.parse(this.cepingHdglCppmxbInfo.hostConfigJson);
    },
    initConfig(id) {
      this.show = false;
    },
     cpDaFen(index,gz,row) {
      let info = {
        xpCode:  this.cepingHdglXpxxbList[index].xpCode,
        cxpCode:  this.cepingHdglXpxxbList[index].cxpCode,
        voteId: this.cepingHdglXpxxbList[index].id,
        itemId: gz.itemId,
        optId: gz.optId,
        sheetType:3,
        voteOptId: gz.id,
        itemType:1,
        userId:this.tableData[index].userId,
      }
      daFenCp(info).then(res => {
        if (res.data.code == "0") {
          this.cepingHdglXpxxb = res.data.data.cepingHdglXpxxb;
          this.tableData = res.data.data.userList;
          this.tableData.forEach(item=>{
                if(item.rySr){
                  item.rySr = item.rySr.substring(0,7)
                }
              })
        } else {
          this.$notify.closeAll();
          this.$notify.error(res.data.msg)
        }
      })
    },
    submit(item){
      var obj ={
        itemId:item.itemId,
        answer:item.answer,
      }
      this.answerJson.push(obj)
      var params ={
        hdId:this.hdId,
        cppId:this.cppId,
        xpCode:this.xpCode,
        answerJson:this.answerJson,
        userId:this.userId,
      }
      daFenCpAnswer(params).then((response)=>{
        if(response.data.code == 0){
          this.voteAnsList=response.data.data.voteAnsList
          // this.$message.success( '提交成功!')
        }
      })
    },
    //校验有没有选择完数据
    yzDf(){
      let cpx = 0;
      var findIndex=this.tableData.findIndex(item=>item.wxOpenid==null||item.wxOpenid==0||item.wxOpenid=='null');
      cpx=findIndex==-1?0:1;
      return cpx;
    },
    //获取脚标说明
    getFooterText(){
      return this.cepingHdglCppmxbInfo.footerText;
    },
    objectSpanMethod({row, column, rowIndex, columnIndex}) {

    },
    tableRowClassName({row, rowIndex}) {
      let fz = this.fzbList.indexOf(this.tableData[rowIndex].zbName1);
      let className = '';
      if (fz % 2 == 0) {
        className = 'cpRowNormal';
      } else {
        className = 'cpRowstripe';
      }
      return className;
    }
  }
}
</script>

<style scoped>
.h_dw_time{
  text-align: left;
}
.sub{
  display: flex;
  justify-content: space-between;
}
</style>

